package advanced.practice._1009;


import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);

        int N=sc.nextInt();
        int M=sc.nextInt();
        int S=sc.nextInt();
        int D=sc.nextInt();

        for(int i=0;i<M;i++){
            int from=sc.nextInt();
            int to=sc.nextInt();
            int dis=sc.nextInt();
            int cost=sc.nextInt();
            HighWay.allWays.add(new HighWay(from,to,dis,cost));
        }

        List<Integer> cities=new ArrayList<>();
        for(int i=0;i<N;i++){
            cities.add(i);
        }
        Route route=findRoute(cities,S,D);//TODO
        for(int c:route.cities){
            System.out.print(c+" ");
        }
        System.out.println(route.totalDistance+" "+route.totalCost);
    }

    static Route findRoute(List<Integer>cities,int from,int to){
        if(from==to){
            return new Route();
        }

        List<HighWay> ways=HighWay.getWaysByCity(cities,from) ;

        int len=ways.size();
        if(len==0){
            return null;
        }

        List <Route>routes=new ArrayList<>();

        for (int i = 0; i < len; i++) {
            Route route=new Route();
            HighWay way=ways.get(i);
            int newFrom=from^way.city2^way.city1;

            route.cities.add(from);
            route.cities.add(newFrom);
            route.totalCost=way.cost;
            route.totalDistance=way.distance;

            List<Integer>subCities=new ArrayList<>();
            subCities.addAll(cities);
            subCities.remove(Integer.valueOf(from));
            Route postRoute=findRoute(subCities,newFrom,to);
            if(postRoute!=null){
                route.addRoute(findRoute(subCities,newFrom,to));//TODO
                routes.add(route);
            }
        }
        Collections.sort(routes);

        if(routes.size()==0){
            return null;
        }
        return routes.get(0);//TODO
    }

    static class Route implements Comparable<Route>{
        List<Integer>cities=new ArrayList<>();
        int totalCost=0;
        int totalDistance=0;

        boolean addRoute(Route other){
            if(other.cities.isEmpty()||(!cities.isEmpty()&&cities.get(cities.size()-1)-other.cities.get(0)!=0)){
                return false;
            }
            for(int i=1;i<other.cities.size();i++){
                cities.add(other.cities.get(i));
            }
            totalCost+=other.totalCost;
            totalDistance+=other.totalDistance;
            return true;
        }
        @Override
        public int compareTo(Route o) {
            int dis=totalDistance-o.totalDistance;
            return dis==0?totalCost-o.totalCost:dis;
        }
    }

    static class HighWay{
        int city1;
        int city2;
        int distance;
        int cost;

        static List<HighWay> allWays=new ArrayList<>();

        static List<HighWay> getWaysByCity(List<Integer>cities,int city){
            List<HighWay> ways=new ArrayList<>();
            for(HighWay hw:allWays){
                if((hw.city1==city||hw.city2==city)&&(cities.contains(hw.city1)&&cities.contains(hw.city2))){
                    ways.add(hw);
                }
            }
            return ways;
        }

        public HighWay(int city1, int city2, int distance, int cost) {
            this.city1 = city1;
            this.city2 = city2;
            this.distance = distance;
            this.cost = cost;
        }
    }
}
